# -*- coding: utf-8 -*-
"""
Created on Thu Dec 03 16:09:26 2015

@author: liliangrong
"""

import time
start = time.clock()


import urllib
import urllib2

#设置代理访问,暂时无法使用,不清楚具体原因
enable_proxy = True
proxy_handler = urllib2.ProxyHandler({"http" : 'http://some-proxy.com:8080'})
null_proxy_handler = urllib2.ProxyHandler({})
if enable_proxy:
    opener = urllib2.build_opener(proxy_handler)
else:
    opener = urllib2.build_opener(null_proxy_handler)
urllib2.install_opener(opener)

#import re
url = "http://www.baidu.com/index.php?tn=56060048_4_pg&ch=12"
user_agent = "Mozilla/5.0 (Windows NT 5.1; rv:35.0) Gecko/20100101 Firefox/35.0"
headers = { "User-Agent" : user_agent }
values = {"name" : "Michael Foord",
        "location" : "Northampton",
        "language" : "Python" }
data = urllib.urlencode(values)
req = urllib2.Request(url,data,headers)
resp = urllib2.urlopen(req)
page = resp.read()
print page

#pattern = re.compile('<section id="content">(.*?)</section>',re.S)
#c = re.search(pattern,page).group()
#print c
print dir(resp)
print dir(page)
print resp.headers


end = time.clock()
print "-----------run time is %f s--------------" % (end-start)

